﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Xml.Serialization;
using Landpy.CruiseControlNet.Infrastructure.Control;

namespace Landpy.CruiseControlNet.FacadeInterface.ConfigurationModule
{
    public class Project : IPrimaryKey
    {
        [Browsable(false)]
        [XmlIgnore]
        public Guid Id { get; private set; }

        [Category("Basic")]
        [Description("The name of your project - this must be unique for any given CruiseControl.NET server.")]
        [XmlAttribute("name")]
        public string Name { get; set; }

        [Category("Basic")]
        [Description("Any security for the project.")]
        [XmlElement("security")]
        public Security Security { get; set; }

        [Category("Basic")]
        [Description("The source control block to use.")]
        [XmlElement("sourcecontrol")]
        public SourceControl SourceControl { get; set; }

        [Category("Basic")]
        [Description(@"Trigger blocks allow you to specify when CruiseControl.NET will start a new integration cycle. " +
                        @"Specifying an empty element (<triggers />) means integrations are only ever forced manually " +
                        @"(for example using CCTray or the Web Dashboard.) Not including a <triggers> element at all means " +
                        @"the project will behave like a <triggers /> element (before 1.4.3 the default when not including a <triggers> was a single Interval Trigger with default configuration).")]
        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [XmlArray("triggers")]
        [XmlArrayItem("intervalTrigger", Type = typeof(IntervalTrigger))]
        [XmlArrayItem("cronTrigger", Type = typeof(CronTrigger))]
        public List<Trigger> Triggers { get; set; }

        [Category("Basic")]
        [Description("A set of Tasks to run as part of the build. A failed task will fail the build and any subsequent tasks will not run. Tasks are run sequentially, in the order they appear in the configuration.")]
        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [XmlArray("tasks")]
        [XmlArrayItem("msbuild", Type = typeof(MSBuild))]
        [XmlArrayItem("nunit", Type = typeof(NUnit))]
        [XmlArrayItem("exec", Type = typeof(Exec))]
        public List<Task> Tasks { get; set; }

        [Category("Basic")]
        [Description("The list of build-completed publishers used by this project.")]
        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [XmlArray("publishers")]
        [XmlArrayItem("xmllogger", Type = typeof(XmlLogger))]
        [XmlArrayItem("email", Type = typeof(Email))]
        [XmlArrayItem("artifactcleanup", Type = typeof(ArtifactCleanup))]
        public List<Publisher> Publishers { get; set; }

        public Project()
        {
            this.Triggers = new List<Trigger>();
            this.Tasks = new List<Task>();
            this.Publishers = new List<Publisher>();
            this.Id = Guid.NewGuid();
        }
    }
}